<%-- 
    Document   : hotelEdit
    Created on : Sep 8, 2011, 1:01:04 PM
    Author     : HIEP
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@taglib uri="http://java.fckeditor.net" prefix="fck" %>

<script>
    function validHotel(){
        var name = document.forms["Hotels"]["name"].value;
        var address = document.forms["Hotels"]["address"].value;
        var phone = document.forms["Hotels"]["phone"].value;
        var price_range = document.forms["Hotels"]["price_range"].value;
        
        if(name =="" || name == null){
            alert("Please enter name of Hotel!");
            return false;
        }
        if(address =="" || address == null){
            alert("Please enter address of Hotel!");
            return false;
        }
        if(phone =="" || phone == null){
            alert("Please enter phone of Hotel!");
            return false;
        }
        if(price_range =="" || price_range == null){
            alert("Please enter price range of Hotel!");
            return false;
        }
        if(!price_range.match(/[0-9]/)){
            alert("Price must number");
            return false;
        }
        if(price_range < 0 || price_range == null){
            alert("Price not valid!");
            return false;
        }
        return true;
    }  
</script>
<!DOCTYPE html>
<div id="content" class="roundedBorders">
    <!-- Title -->
    <div id="title" class="b2">
        <h2>Manage Hotels</h2>
    </div>
    <!-- Title -->
    <!-- Inner Content -->
    <div id="innerContent">
        <c:if test="${item == null}">
            <!-- Form -->
            <html:form onsubmit="return validHotel();" action="/HotelAction.do?method=add" method="POST">
                <div class="fieldset fieldsetBlock active tabs">
                    <div class="header">
                        <h3>Add New Hotel</h3>
                    </div>
                    <div class="tabs">
                        <fieldset id="fieldset1" >
                            <legend>Post content</legend>
                            <div class="field required">
                                <label>Name</label> 
                                <input type="text" class="text" name="name" id="name"/> 
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Address</label> 
                                <input type="text" class="text" name="address" id="address"/> 
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Phone</label> 
                                <input type="text" class="text" name="phone" id="phone"/> 
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Description</label>
                                <fck:editor height="300px" width="670px" instanceName="description"></fck:editor>
                                </div>
                                <div class="field required">
                                    <label>Price Range</label> 
                                    <input type="text" class="text" name="price_range" id="price_range"/> 
                                    <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                                </div>
                                <div class="field required">
                                    <label>Location</label> 
                                    <select name="location_id">
                                    <c:forEach items="${locationList}" var="loca">
                                        <option value="${loca.id}">${loca.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div id="buttom1">
                                <strong>
                                    <html:submit value="Add Hotel" styleClass="buttom_form"/>
                                </strong>
                                <strong>    
                                    <input type="reset" value="Reset" class="buttom_form"/>
                                </strong>
                            </div>
                        </fieldset>
                    </div>
                    <span class="bBR"></span>
                </div>
            </html:form>
            <!-- /Form -->
        </c:if>
        <c:if test="${item != null}">
            <!-- Form -->
            <html:form onsubmit="return validHotel();" action="/HotelAction.do?method=update" method="POST">
                <div class="fieldset fieldsetBlock active tabs">
                    <div class="header">
                        <h3>Edit Hotel</h3>
                    </div>
                    <div class="tabs">
                        <fieldset id="fieldset1" >
                            <legend>Post content</legend>
                            <input hidden="true" value="${item.id}" type="hidden" name="id"/>
                            <div class="field required">
                                <label>Name</label> 
                                <input type="text" class="text" name="name" id="name" value="${item.name}"/> 
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Address</label> 
                                <input type="text" class="text" name="address" id="address" value="${item.address}"/> 
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Phone</label> 
                                <input type="text" class="text" name="phone" id="phone" value="${item.phone}"/> 
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Description</label> 
                                <fck:editor height="300px" width="670px" value="${item.description}" instanceName="description"></fck:editor>
                            </div>
                            <div class="field required">
                                <label>Price Range</label> 
                                <input type="text" class="text" name="price_range" id="price_range" value="${item.price_range}"/> 
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Location</label> 
                                <select name="location_id">
                                    <c:forEach items="${locationList}" var="loca">
                                        <c:if test="${loca.id == item.location_id}">
                                            <option selected="selected" value="${loca.id}">${loca.name}</option>
                                        </c:if>
                                        <option value="${loca.id}">${loca.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div id="buttom1">
                                <strong>
                                    <html:submit value="Update" styleClass="buttom_form"/>
                                </strong>
                                <strong>    
                                    <html:cancel value="Cancel" styleClass="buttom_form"/>
                                </strong>
                            </div>
                        </fieldset>
                    </div>
                    <span class="bBR"></span>
                </div>
            </html:form>
            <!-- /Form -->
        </c:if>
    </div>
    <!-- /Inner Content -->
    <div class="bBottom"><div></div></div>
</div>